package it.slkfarm.log;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import java.util.logging.XMLFormatter;

import android.os.Environment;

public class AppLogger 
{
	/**
	 * @uml.property  name="logFile"
	 */
	private File logFile;
	
	public AppLogger(String device)
	{
		logFile = new File("data/data/it.slkfarm.android/files/log - "+device+".txt");
	}
	
	public void appendLog(LogData log)
    {       
       if (!logFile.exists())
       {
          try
          {
             logFile.createNewFile();
          } 
          catch (IOException e)
          {
             e.printStackTrace();
          }
       }
       try
       {
          BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); 
          SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy - HH:mm:ss");
          String date = sdf.format(new Date());
          buf.write(log.getLog());
          buf.close();

       }
       catch (IOException e)
       {
           e.printStackTrace();
       }
    }
}
